{
  "cells": [
    {
      "cell_type": "markdown",
      "source": [
        "# Array Selection Numpy"
      ],
      "metadata": {}
    },
    {
      "cell_type": "code",
      "source": [
        "import numpy as np\n",
        "import pandas as pd\n",
        "import matplotlib.pyplot as plt\n",
        "import seaborn as sns\n",
        "sns.set(style=\"white\", color_codes=True)\n",
        "\n",
        "import warnings\n",
        "warnings.filterwarnings(\"ignore\")\n",
        "\n",
        "# fix_yahoo_finance is used to fetch data \n",
        "import fix_yahoo_finance as yf\n",
        "yf.pdr_override()"
      ],
      "outputs": [],
      "execution_count": 1,
      "metadata": {
        "collapsed": false,
        "outputHidden": false,
        "inputHidden": false
      }
    },
    {
      "cell_type": "code",
      "source": [
        "# input\n",
        "symbol = 'AMD'\n",
        "start = '2014-01-01'\n",
        "end = '2019-01-01'\n",
        "\n",
        "# Read data \n",
        "dataset = yf.download(symbol,start,end)\n",
        "\n",
        "# View Columns\n",
        "dataset.head()"
      ],
      "outputs": [
        {
          "output_type": "stream",
          "name": "stdout",
          "text": [
            "[*********************100%***********************]  1 of 1 downloaded\n"
          ]
        },
        {
          "output_type": "execute_result",
          "execution_count": 2,
          "data": {
            "text/html": [
              "<div>\n",
              "<style scoped>\n",
              "    .dataframe tbody tr th:only-of-type {\n",
              "        vertical-align: middle;\n",
              "    }\n",
              "\n",
              "    .dataframe tbody tr th {\n",
              "        vertical-align: top;\n",
              "    }\n",
              "\n",
              "    .dataframe thead th {\n",
              "        text-align: right;\n",
              "    }\n",
              "</style>\n",
              "<table border=\"1\" class=\"dataframe\">\n",
              "  <thead>\n",
              "    <tr style=\"text-align: right;\">\n",
              "      <th></th>\n",
              "      <th>Open</th>\n",
              "      <th>High</th>\n",
              "      <th>Low</th>\n",
              "      <th>Close</th>\n",
              "      <th>Adj Close</th>\n",
              "      <th>Volume</th>\n",
              "    </tr>\n",
              "    <tr>\n",
              "      <th>Date</th>\n",
              "      <th></th>\n",
              "      <th></th>\n",
              "      <th></th>\n",
              "      <th></th>\n",
              "      <th></th>\n",
              "      <th></th>\n",
              "    </tr>\n",
              "  </thead>\n",
              "  <tbody>\n",
              "    <tr>\n",
              "      <th>2014-01-02</th>\n",
              "      <td>3.85</td>\n",
              "      <td>3.98</td>\n",
              "      <td>3.84</td>\n",
              "      <td>3.95</td>\n",
              "      <td>3.95</td>\n",
              "      <td>20548400</td>\n",
              "    </tr>\n",
              "    <tr>\n",
              "      <th>2014-01-03</th>\n",
              "      <td>3.98</td>\n",
              "      <td>4.00</td>\n",
              "      <td>3.88</td>\n",
              "      <td>4.00</td>\n",
              "      <td>4.00</td>\n",
              "      <td>22887200</td>\n",
              "    </tr>\n",
              "    <tr>\n",
              "      <th>2014-01-06</th>\n",
              "      <td>4.01</td>\n",
              "      <td>4.18</td>\n",
              "      <td>3.99</td>\n",
              "      <td>4.13</td>\n",
              "      <td>4.13</td>\n",
              "      <td>42398300</td>\n",
              "    </tr>\n",
              "    <tr>\n",
              "      <th>2014-01-07</th>\n",
              "      <td>4.19</td>\n",
              "      <td>4.25</td>\n",
              "      <td>4.11</td>\n",
              "      <td>4.18</td>\n",
              "      <td>4.18</td>\n",
              "      <td>42932100</td>\n",
              "    </tr>\n",
              "    <tr>\n",
              "      <th>2014-01-08</th>\n",
              "      <td>4.23</td>\n",
              "      <td>4.26</td>\n",
              "      <td>4.14</td>\n",
              "      <td>4.18</td>\n",
              "      <td>4.18</td>\n",
              "      <td>30678700</td>\n",
              "    </tr>\n",
              "  </tbody>\n",
              "</table>\n",
              "</div>"
            ],
            "text/plain": [
              "            Open  High   Low  Close  Adj Close    Volume\n",
              "Date                                                    \n",
              "2014-01-02  3.85  3.98  3.84   3.95       3.95  20548400\n",
              "2014-01-03  3.98  4.00  3.88   4.00       4.00  22887200\n",
              "2014-01-06  4.01  4.18  3.99   4.13       4.13  42398300\n",
              "2014-01-07  4.19  4.25  4.11   4.18       4.18  42932100\n",
              "2014-01-08  4.23  4.26  4.14   4.18       4.18  30678700"
            ]
          },
          "metadata": {}
        }
      ],
      "execution_count": 2,
      "metadata": {
        "collapsed": false,
        "outputHidden": false,
        "inputHidden": false
      }
    },
    {
      "cell_type": "code",
      "source": [
        "# Create Data\n",
        "dataset['Open_Close'] = (dataset['Open'] - dataset['Adj Close'])/dataset['Open']\n",
        "dataset['High_Low'] = (dataset['High'] - dataset['Low'])/dataset['Low']\n",
        "dataset['Increase_Decrease'] = np.where(dataset['Volume'].shift(-1) > dataset['Volume'],1,0)\n",
        "dataset['Buy_Sell_on_Open'] = np.where(dataset['Open'].shift(-1) > dataset['Open'],1,0)\n",
        "dataset['Buy_Sell'] = np.where(dataset['Adj Close'].shift(-1) > dataset['Adj Close'],1,0)\n",
        "dataset['Returns'] = dataset['Adj Close'].pct_change()\n",
        "dataset = dataset.dropna()"
      ],
      "outputs": [],
      "execution_count": 3,
      "metadata": {
        "collapsed": false,
        "outputHidden": false,
        "inputHidden": false
      }
    },
    {
      "cell_type": "code",
      "source": [
        "dataset.head()"
      ],
      "outputs": [
        {
          "output_type": "execute_result",
          "execution_count": 4,
          "data": {
            "text/html": [
              "<div>\n",
              "<style scoped>\n",
              "    .dataframe tbody tr th:only-of-type {\n",
              "        vertical-align: middle;\n",
              "    }\n",
              "\n",
              "    .dataframe tbody tr th {\n",
              "        vertical-align: top;\n",
              "    }\n",
              "\n",
              "    .dataframe thead th {\n",
              "        text-align: right;\n",
              "    }\n",
              "</style>\n",
              "<table border=\"1\" class=\"dataframe\">\n",
              "  <thead>\n",
              "    <tr style=\"text-align: right;\">\n",
              "      <th></th>\n",
              "      <th>Open</th>\n",
              "      <th>High</th>\n",
              "      <th>Low</th>\n",
              "      <th>Close</th>\n",
              "      <th>Adj Close</th>\n",
              "      <th>Volume</th>\n",
              "      <th>Open_Close</th>\n",
              "      <th>High_Low</th>\n",
              "      <th>Increase_Decrease</th>\n",
              "      <th>Buy_Sell_on_Open</th>\n",
              "      <th>Buy_Sell</th>\n",
              "      <th>Returns</th>\n",
              "    </tr>\n",
              "    <tr>\n",
              "      <th>Date</th>\n",
              "      <th></th>\n",
              "      <th></th>\n",
              "      <th></th>\n",
              "      <th></th>\n",
              "      <th></th>\n",
              "      <th></th>\n",
              "      <th></th>\n",
              "      <th></th>\n",
              "      <th></th>\n",
              "      <th></th>\n",
              "      <th></th>\n",
              "      <th></th>\n",
              "    </tr>\n",
              "  </thead>\n",
              "  <tbody>\n",
              "    <tr>\n",
              "      <th>2014-01-03</th>\n",
              "      <td>3.98</td>\n",
              "      <td>4.00</td>\n",
              "      <td>3.88</td>\n",
              "      <td>4.00</td>\n",
              "      <td>4.00</td>\n",
              "      <td>22887200</td>\n",
              "      <td>-0.005025</td>\n",
              "      <td>0.030928</td>\n",
              "      <td>1</td>\n",
              "      <td>1</td>\n",
              "      <td>1</td>\n",
              "      <td>0.012658</td>\n",
              "    </tr>\n",
              "    <tr>\n",
              "      <th>2014-01-06</th>\n",
              "      <td>4.01</td>\n",
              "      <td>4.18</td>\n",
              "      <td>3.99</td>\n",
              "      <td>4.13</td>\n",
              "      <td>4.13</td>\n",
              "      <td>42398300</td>\n",
              "      <td>-0.029925</td>\n",
              "      <td>0.047619</td>\n",
              "      <td>1</td>\n",
              "      <td>1</td>\n",
              "      <td>1</td>\n",
              "      <td>0.032500</td>\n",
              "    </tr>\n",
              "    <tr>\n",
              "      <th>2014-01-07</th>\n",
              "      <td>4.19</td>\n",
              "      <td>4.25</td>\n",
              "      <td>4.11</td>\n",
              "      <td>4.18</td>\n",
              "      <td>4.18</td>\n",
              "      <td>42932100</td>\n",
              "      <td>0.002387</td>\n",
              "      <td>0.034063</td>\n",
              "      <td>0</td>\n",
              "      <td>1</td>\n",
              "      <td>0</td>\n",
              "      <td>0.012107</td>\n",
              "    </tr>\n",
              "    <tr>\n",
              "      <th>2014-01-08</th>\n",
              "      <td>4.23</td>\n",
              "      <td>4.26</td>\n",
              "      <td>4.14</td>\n",
              "      <td>4.18</td>\n",
              "      <td>4.18</td>\n",
              "      <td>30678700</td>\n",
              "      <td>0.011820</td>\n",
              "      <td>0.028986</td>\n",
              "      <td>0</td>\n",
              "      <td>0</td>\n",
              "      <td>0</td>\n",
              "      <td>0.000000</td>\n",
              "    </tr>\n",
              "    <tr>\n",
              "      <th>2014-01-09</th>\n",
              "      <td>4.20</td>\n",
              "      <td>4.23</td>\n",
              "      <td>4.05</td>\n",
              "      <td>4.09</td>\n",
              "      <td>4.09</td>\n",
              "      <td>30667600</td>\n",
              "      <td>0.026190</td>\n",
              "      <td>0.044444</td>\n",
              "      <td>0</td>\n",
              "      <td>0</td>\n",
              "      <td>1</td>\n",
              "      <td>-0.021531</td>\n",
              "    </tr>\n",
              "  </tbody>\n",
              "</table>\n",
              "</div>"
            ],
            "text/plain": [
              "            Open  High   Low  Close  Adj Close    Volume  Open_Close  \\\n",
              "Date                                                                   \n",
              "2014-01-03  3.98  4.00  3.88   4.00       4.00  22887200   -0.005025   \n",
              "2014-01-06  4.01  4.18  3.99   4.13       4.13  42398300   -0.029925   \n",
              "2014-01-07  4.19  4.25  4.11   4.18       4.18  42932100    0.002387   \n",
              "2014-01-08  4.23  4.26  4.14   4.18       4.18  30678700    0.011820   \n",
              "2014-01-09  4.20  4.23  4.05   4.09       4.09  30667600    0.026190   \n",
              "\n",
              "            High_Low  Increase_Decrease  Buy_Sell_on_Open  Buy_Sell   Returns  \n",
              "Date                                                                           \n",
              "2014-01-03  0.030928                  1                 1         1  0.012658  \n",
              "2014-01-06  0.047619                  1                 1         1  0.032500  \n",
              "2014-01-07  0.034063                  0                 1         0  0.012107  \n",
              "2014-01-08  0.028986                  0                 0         0  0.000000  \n",
              "2014-01-09  0.044444                  0                 0         1 -0.021531  "
            ]
          },
          "metadata": {}
        }
      ],
      "execution_count": 4,
      "metadata": {
        "collapsed": false,
        "outputHidden": false,
        "inputHidden": false
      }
    },
    {
      "cell_type": "markdown",
      "source": [
        "## Feature Selection in Array (Numpy)"
      ],
      "metadata": {}
    },
    {
      "cell_type": "code",
      "source": [
        "feature_data = np.asarray(dataset)"
      ],
      "outputs": [],
      "execution_count": 5,
      "metadata": {}
    },
    {
      "cell_type": "code",
      "source": [
        "feature_data"
      ],
      "outputs": [
        {
          "output_type": "execute_result",
          "execution_count": 6,
          "data": {
            "text/plain": [
              "array([[  3.98000000e+00,   4.00000000e+00,   3.88000000e+00, ...,\n",
              "          1.00000000e+00,   1.00000000e+00,   1.26582278e-02],\n",
              "       [  4.01000000e+00,   4.18000000e+00,   3.99000000e+00, ...,\n",
              "          1.00000000e+00,   1.00000000e+00,   3.25000000e-02],\n",
              "       [  4.19000000e+00,   4.25000000e+00,   4.11000000e+00, ...,\n",
              "          1.00000000e+00,   0.00000000e+00,   1.21065375e-02],\n",
              "       ..., \n",
              "       [  1.74300000e+01,   1.77400000e+01,   1.64400010e+01, ...,\n",
              "          1.00000000e+00,   1.00000000e+00,  -2.29050279e-02],\n",
              "       [  1.75300010e+01,   1.83099990e+01,   1.71399990e+01, ...,\n",
              "          1.00000000e+00,   1.00000000e+00,   1.88679245e-02],\n",
              "       [  1.81500000e+01,   1.85100000e+01,   1.78500000e+01, ...,\n",
              "          0.00000000e+00,   0.00000000e+00,   3.59146465e-02]])"
            ]
          },
          "metadata": {}
        }
      ],
      "execution_count": 6,
      "metadata": {
        "collapsed": false,
        "outputHidden": false,
        "inputHidden": false
      }
    },
    {
      "cell_type": "code",
      "source": [
        "type(feature_data)"
      ],
      "outputs": [
        {
          "output_type": "execute_result",
          "execution_count": 7,
          "data": {
            "text/plain": [
              "numpy.ndarray"
            ]
          },
          "metadata": {}
        }
      ],
      "execution_count": 7,
      "metadata": {
        "collapsed": false,
        "outputHidden": false,
        "inputHidden": false
      }
    },
    {
      "cell_type": "code",
      "source": [
        "feature_data[0]"
      ],
      "outputs": [
        {
          "output_type": "execute_result",
          "execution_count": 8,
          "data": {
            "text/plain": [
              "array([  3.98000000e+00,   4.00000000e+00,   3.88000000e+00,\n",
              "         4.00000000e+00,   4.00000000e+00,   2.28872000e+07,\n",
              "        -5.02512563e-03,   3.09278351e-02,   1.00000000e+00,\n",
              "         1.00000000e+00,   1.00000000e+00,   1.26582278e-02])"
            ]
          },
          "metadata": {}
        }
      ],
      "execution_count": 8,
      "metadata": {
        "collapsed": false,
        "outputHidden": false,
        "inputHidden": false
      }
    },
    {
      "cell_type": "code",
      "source": [
        "feature_data[0][1]"
      ],
      "outputs": [
        {
          "output_type": "execute_result",
          "execution_count": 9,
          "data": {
            "text/plain": [
              "4.0"
            ]
          },
          "metadata": {}
        }
      ],
      "execution_count": 9,
      "metadata": {
        "collapsed": false,
        "outputHidden": false,
        "inputHidden": false
      }
    },
    {
      "cell_type": "code",
      "source": [
        "# row 1, all columns\n",
        "feature_data[1, :]"
      ],
      "outputs": [
        {
          "output_type": "execute_result",
          "execution_count": 10,
          "data": {
            "text/plain": [
              "array([  4.01000000e+00,   4.18000000e+00,   3.99000000e+00,\n",
              "         4.13000000e+00,   4.13000000e+00,   4.23983000e+07,\n",
              "        -2.99251870e-02,   4.76190476e-02,   1.00000000e+00,\n",
              "         1.00000000e+00,   1.00000000e+00,   3.25000000e-02])"
            ]
          },
          "metadata": {}
        }
      ],
      "execution_count": 10,
      "metadata": {
        "collapsed": false,
        "outputHidden": false,
        "inputHidden": false
      }
    },
    {
      "cell_type": "code",
      "source": [
        "# row 0, column 0 to 1\n",
        "# numpy includes the first, and excludes the last\n",
        "# use :2 to reach 1\n",
        "feature_data[0, :2]"
      ],
      "outputs": [
        {
          "output_type": "execute_result",
          "execution_count": 11,
          "data": {
            "text/plain": [
              "array([ 3.98,  4.  ])"
            ]
          },
          "metadata": {}
        }
      ],
      "execution_count": 11,
      "metadata": {
        "collapsed": false,
        "outputHidden": false,
        "inputHidden": false
      }
    },
    {
      "cell_type": "code",
      "source": [
        "# one column with one row in array\n",
        "feature_data[:,0]"
      ],
      "outputs": [
        {
          "output_type": "execute_result",
          "execution_count": 12,
          "data": {
            "text/plain": [
              "array([  3.98    ,   4.01    ,   4.19    , ...,  17.43    ,  17.530001,\n",
              "        18.15    ])"
            ]
          },
          "metadata": {}
        }
      ],
      "execution_count": 12,
      "metadata": {
        "collapsed": false,
        "outputHidden": false,
        "inputHidden": false
      }
    },
    {
      "cell_type": "code",
      "source": [
        "# This show in rows of one column \n",
        "feature_data[:,[0]]"
      ],
      "outputs": [
        {
          "output_type": "execute_result",
          "execution_count": 13,
          "data": {
            "text/plain": [
              "array([[  3.98    ],\n",
              "       [  4.01    ],\n",
              "       [  4.19    ],\n",
              "       ..., \n",
              "       [ 17.43    ],\n",
              "       [ 17.530001],\n",
              "       [ 18.15    ]])"
            ]
          },
          "metadata": {}
        }
      ],
      "execution_count": 13,
      "metadata": {
        "collapsed": false,
        "outputHidden": false,
        "inputHidden": false
      }
    },
    {
      "cell_type": "code",
      "source": [
        "np.hstack((feature_data, feature_data[:,[0]]))"
      ],
      "outputs": [
        {
          "output_type": "execute_result",
          "execution_count": 14,
          "data": {
            "text/plain": [
              "array([[  3.98000000e+00,   4.00000000e+00,   3.88000000e+00, ...,\n",
              "          1.00000000e+00,   1.26582278e-02,   3.98000000e+00],\n",
              "       [  4.01000000e+00,   4.18000000e+00,   3.99000000e+00, ...,\n",
              "          1.00000000e+00,   3.25000000e-02,   4.01000000e+00],\n",
              "       [  4.19000000e+00,   4.25000000e+00,   4.11000000e+00, ...,\n",
              "          0.00000000e+00,   1.21065375e-02,   4.19000000e+00],\n",
              "       ..., \n",
              "       [  1.74300000e+01,   1.77400000e+01,   1.64400010e+01, ...,\n",
              "          1.00000000e+00,  -2.29050279e-02,   1.74300000e+01],\n",
              "       [  1.75300010e+01,   1.83099990e+01,   1.71399990e+01, ...,\n",
              "          1.00000000e+00,   1.88679245e-02,   1.75300010e+01],\n",
              "       [  1.81500000e+01,   1.85100000e+01,   1.78500000e+01, ...,\n",
              "          0.00000000e+00,   3.59146465e-02,   1.81500000e+01]])"
            ]
          },
          "metadata": {}
        }
      ],
      "execution_count": 14,
      "metadata": {
        "collapsed": false,
        "outputHidden": false,
        "inputHidden": false
      }
    },
    {
      "cell_type": "code",
      "source": [
        "# Use transpose of particular column\n",
        "feature_data.T[0]"
      ],
      "outputs": [
        {
          "output_type": "execute_result",
          "execution_count": 15,
          "data": {
            "text/plain": [
              "array([  3.98    ,   4.01    ,   4.19    , ...,  17.43    ,  17.530001,\n",
              "        18.15    ])"
            ]
          },
          "metadata": {}
        }
      ],
      "execution_count": 15,
      "metadata": {
        "collapsed": false,
        "outputHidden": false,
        "inputHidden": false
      }
    },
    {
      "cell_type": "code",
      "source": [
        "feature_data.shape[0]"
      ],
      "outputs": [
        {
          "output_type": "execute_result",
          "execution_count": 16,
          "data": {
            "text/plain": [
              "1257"
            ]
          },
          "metadata": {}
        }
      ],
      "execution_count": 16,
      "metadata": {
        "collapsed": false,
        "outputHidden": false,
        "inputHidden": false
      }
    },
    {
      "cell_type": "code",
      "source": [
        "# Get more than one column\n",
        "feature_data[:,[0,2]]"
      ],
      "outputs": [
        {
          "output_type": "execute_result",
          "execution_count": 17,
          "data": {
            "text/plain": [
              "array([[  3.98    ,   3.88    ],\n",
              "       [  4.01    ,   3.99    ],\n",
              "       [  4.19    ,   4.11    ],\n",
              "       ..., \n",
              "       [ 17.43    ,  16.440001],\n",
              "       [ 17.530001,  17.139999],\n",
              "       [ 18.15    ,  17.85    ]])"
            ]
          },
          "metadata": {}
        }
      ],
      "execution_count": 17,
      "metadata": {
        "collapsed": false,
        "outputHidden": false,
        "inputHidden": false
      }
    },
    {
      "cell_type": "code",
      "source": [
        "# Remove elements - Delete the last element\n",
        "r = feature_data[:-1]\n",
        "r"
      ],
      "outputs": [
        {
          "output_type": "execute_result",
          "execution_count": 18,
          "data": {
            "text/plain": [
              "array([[  3.98000000e+00,   4.00000000e+00,   3.88000000e+00, ...,\n",
              "          1.00000000e+00,   1.00000000e+00,   1.26582278e-02],\n",
              "       [  4.01000000e+00,   4.18000000e+00,   3.99000000e+00, ...,\n",
              "          1.00000000e+00,   1.00000000e+00,   3.25000000e-02],\n",
              "       [  4.19000000e+00,   4.25000000e+00,   4.11000000e+00, ...,\n",
              "          1.00000000e+00,   0.00000000e+00,   1.21065375e-02],\n",
              "       ..., \n",
              "       [  1.68799990e+01,   1.79100000e+01,   1.60300010e+01, ...,\n",
              "          1.00000000e+00,   0.00000000e+00,   7.50750751e-02],\n",
              "       [  1.74300000e+01,   1.77400000e+01,   1.64400010e+01, ...,\n",
              "          1.00000000e+00,   1.00000000e+00,  -2.29050279e-02],\n",
              "       [  1.75300010e+01,   1.83099990e+01,   1.71399990e+01, ...,\n",
              "          1.00000000e+00,   1.00000000e+00,   1.88679245e-02]])"
            ]
          },
          "metadata": {}
        }
      ],
      "execution_count": 18,
      "metadata": {
        "collapsed": false,
        "outputHidden": false,
        "inputHidden": false
      }
    },
    {
      "cell_type": "code",
      "source": [
        "r =np.delete(r,0) # Delete the first element\n",
        "r"
      ],
      "outputs": [
        {
          "output_type": "execute_result",
          "execution_count": 19,
          "data": {
            "text/plain": [
              "array([ 4.        ,  3.88      ,  4.        , ...,  1.        ,\n",
              "        1.        ,  0.01886792])"
            ]
          },
          "metadata": {}
        }
      ],
      "execution_count": 19,
      "metadata": {
        "collapsed": false,
        "outputHidden": false,
        "inputHidden": false
      }
    },
    {
      "cell_type": "code",
      "source": [
        "print(\"Compare 2 array data\")\n",
        "print(\"Original Data:\")\n",
        "print(feature_data)\n",
        "print(\"-\" * 50)\n",
        "a=np.delete(feature_data, 0, axis=0) # Delete the first column\n",
        "print(\"New array data:\\n\", a)"
      ],
      "outputs": [
        {
          "output_type": "stream",
          "name": "stdout",
          "text": [
            "Compare 2 array data\n",
            "Original Data:\n",
            "[[  3.98000000e+00   4.00000000e+00   3.88000000e+00 ...,   1.00000000e+00\n",
            "    1.00000000e+00   1.26582278e-02]\n",
            " [  4.01000000e+00   4.18000000e+00   3.99000000e+00 ...,   1.00000000e+00\n",
            "    1.00000000e+00   3.25000000e-02]\n",
            " [  4.19000000e+00   4.25000000e+00   4.11000000e+00 ...,   1.00000000e+00\n",
            "    0.00000000e+00   1.21065375e-02]\n",
            " ..., \n",
            " [  1.74300000e+01   1.77400000e+01   1.64400010e+01 ...,   1.00000000e+00\n",
            "    1.00000000e+00  -2.29050279e-02]\n",
            " [  1.75300010e+01   1.83099990e+01   1.71399990e+01 ...,   1.00000000e+00\n",
            "    1.00000000e+00   1.88679245e-02]\n",
            " [  1.81500000e+01   1.85100000e+01   1.78500000e+01 ...,   0.00000000e+00\n",
            "    0.00000000e+00   3.59146465e-02]]\n",
            "--------------------------------------------------\n",
            "New array data:\n",
            " [[  4.01000000e+00   4.18000000e+00   3.99000000e+00 ...,   1.00000000e+00\n",
            "    1.00000000e+00   3.25000000e-02]\n",
            " [  4.19000000e+00   4.25000000e+00   4.11000000e+00 ...,   1.00000000e+00\n",
            "    0.00000000e+00   1.21065375e-02]\n",
            " [  4.23000000e+00   4.26000000e+00   4.14000000e+00 ...,   0.00000000e+00\n",
            "    0.00000000e+00   0.00000000e+00]\n",
            " ..., \n",
            " [  1.74300000e+01   1.77400000e+01   1.64400010e+01 ...,   1.00000000e+00\n",
            "    1.00000000e+00  -2.29050279e-02]\n",
            " [  1.75300010e+01   1.83099990e+01   1.71399990e+01 ...,   1.00000000e+00\n",
            "    1.00000000e+00   1.88679245e-02]\n",
            " [  1.81500000e+01   1.85100000e+01   1.78500000e+01 ...,   0.00000000e+00\n",
            "    0.00000000e+00   3.59146465e-02]]\n"
          ]
        }
      ],
      "execution_count": 20,
      "metadata": {
        "collapsed": false,
        "outputHidden": false,
        "inputHidden": false
      }
    },
    {
      "cell_type": "code",
      "source": [
        "print('Example Stock with ll Features: ', '\\n', feature_data[0], 'Stock Data Features')"
      ],
      "outputs": [
        {
          "output_type": "stream",
          "name": "stdout",
          "text": [
            "Example Stock with ll Features:  \n",
            " [  3.98000000e+00   4.00000000e+00   3.88000000e+00   4.00000000e+00\n",
            "   4.00000000e+00   2.28872000e+07  -5.02512563e-03   3.09278351e-02\n",
            "   1.00000000e+00   1.00000000e+00   1.00000000e+00   1.26582278e-02] Stock Data Features\n"
          ]
        }
      ],
      "execution_count": 21,
      "metadata": {
        "collapsed": false,
        "outputHidden": false,
        "inputHidden": false
      }
    },
    {
      "cell_type": "code",
      "source": [
        "selected_features = feature_data[:, [1, 2, 3, 11]]"
      ],
      "outputs": [],
      "execution_count": 22,
      "metadata": {
        "collapsed": false,
        "outputHidden": false,
        "inputHidden": false
      }
    },
    {
      "cell_type": "code",
      "source": [
        "x_data_features = selected_features[1:, :]\n",
        "x_data_features[x_data_features == ''] = 0.0\n",
        "x_data = x_data_features\n",
        "selected_feature_labels = selected_features[0, 1:]\n",
        "print('Selected Feature Names: \\n', selected_feature_labels)\n",
        "print('First few Stocks with Features, no Lables: ', '\\n', x_data[0:2, :], ' ...')\n",
        "print(np.size(x_data[:, 0]), 'Stocks by', np.size(x_data[0, :]), 'Features')"
      ],
      "outputs": [
        {
          "output_type": "stream",
          "name": "stdout",
          "text": [
            "Selected Feature Names: \n",
            " [ 3.88        4.          0.01265823]\n",
            "First few Stocks with Features, no Lables:  \n",
            " [[ 4.18        3.99        4.13        0.0325    ]\n",
            " [ 4.25        4.11        4.18        0.01210654]]  ...\n",
            "1256 Stocks by 4 Features\n"
          ]
        }
      ],
      "execution_count": 23,
      "metadata": {
        "collapsed": false,
        "outputHidden": false,
        "inputHidden": false
      }
    },
    {
      "cell_type": "code",
      "source": [
        "# Place dataset into input (X) and output (Y) variables\n",
        "x_strings = x_data_features[:, 1:]  # take off tickers, as they can't be tensor'd\n",
        "raw_X = x_strings.astype(np.float)  # convert strings to float\n",
        "# num_of_features = np.size(raw_X[0, :])\n",
        "print('Features for Tensor: ', np.size(raw_X[0, :]))"
      ],
      "outputs": [
        {
          "output_type": "stream",
          "name": "stdout",
          "text": [
            "Features for Tensor:  3\n"
          ]
        }
      ],
      "execution_count": 24,
      "metadata": {
        "collapsed": false,
        "outputHidden": false,
        "inputHidden": false
      }
    }
  ],
  "metadata": {
    "kernel_info": {
      "name": "python3"
    },
    "language_info": {
      "file_extension": ".py",
      "mimetype": "text/x-python",
      "version": "3.5.5",
      "name": "python",
      "pygments_lexer": "ipython3",
      "nbconvert_exporter": "python",
      "codemirror_mode": {
        "version": 3,
        "name": "ipython"
      }
    },
    "kernelspec": {
      "name": "python3",
      "language": "python",
      "display_name": "Python 3"
    },
    "nteract": {
      "version": "0.12.2"
    }
  },
  "nbformat": 4,
  "nbformat_minor": 4
}